<?php $this->load->view('layout/header_data_form');?>
<script type="text/javascript" src="<?php echo js_link('jquery.highlightFade.js');?>"></script>
<script type="text/javascript" src="<?php echo js_link('jquery.js');?>"></script>

<script type="text/javascript">
function addFormField() {
	var id = document.getElementById("hidd").value;
	$("#divTxt").append("<div id='row" + id + "' class='width'><input type='text' size='25' name='loans_duration[]' id='txt" + id + "' class='field' /><input name='loans_id[]' type='hidden' /> <input type='text' size='25' name='loans_amount[]' id='txt" + id + "' class='field' /> <a href='#' onClick='removeFormField(\"#row" + id + "\"); return false;' class='delete'>Delete</a></div>");
	
	
	$('#row' + id).highlightFade({
		speed:1000
	});
	
	id = (id - 1) + 2;
	document.getElementById("hidd").value = id;
}

function removeFormField(id) {
	$(id).remove();
}
</script>
<script type="text/javascript">
function addFormField2() {
	var id = document.getElementById("depen").value;
	$("#divdepen").append("<div id='row2" + id + "' class='width'><input name='dep_id[]' type='hidden' /><input type='text' size='25' name='dep_duration[]' id='txt" + id + "' class='field' /> <input type='text' size='25' name='dep_amount[]' id='txt" + id + "' class='field' /> <a href='#' onClick='removeFormField(\"#row2" + id + "\"); return false;' class='delete'>Delete</a></div>");
	
	
	$('#row' + id).highlightFade({
		speed:1000
	});
	
	id = (id - 1) + 2;
	document.getElementById("depen").value = id;
}

function removeFormField(id) {
	$(id).remove();
}
</script>

<script type="text/javascript">

function showhide(divid, state){
document.getElementById(divid).style.display=state
}

</script>

<?php $this->load->view('layout/logo');?>

<script>
function showMe (it, box) {
var vis = (box.checked) ? "visible" : "hidden";
document.getElementById(it).style.visibility = vis;
}
</script>
<div id="wrap">
  <form id="form1" name="form1" method="post" action="">
    <table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="600">
        
<select name="child" class="field" id="child" onchange="location.href='<?php echo base_url().'prot_death/?act=';?>'+document.getElementById('child').value">
                <option value="0" selected="selected">--- Select One---</option>
                <option <?php echo(isset($_GET['act']) && $_GET['act'] == 'Income' ? 'selected="selected"' : '');?> value="Income">Income Approach</option>
                <option <?php echo(isset($_GET['act']) && $_GET['act'] == 'Expense' ? 'selected="selected"' : '');?> value="Expense">Expense Approach</option>
            </select><br />
<br />          </td>
      </tr>
      
      <tr>
        <td valign="top">
        <?php if(isset($_GET['act']) && $_GET['act'] == 'Income'):?>
        <div id="income">
          <table border="0" cellpadding="7" cellspacing="0">
            <tr>
              <td width="130" align="right"><strong>Yearly Income:</strong></td>
              <td><input name="textfield5" value="<?php echo($row && isset($row['yearly_income']) ? $row['yearly_income'] : '');?>" type="text" class="field" id="textfield5" size="20" /></td>
            </tr>
            <tr>
              <td align="right"><strong>% to Protect:</strong></td>
              <td><input name="textfield2" value="<?php echo($row && isset($row['percent_of_protection']) ? $row['percent_of_protection'] : '');?>" type="text" class="field" id="textfield2" size="20" /></td>
            </tr>
            <tr>
              <td align="right"><strong>Number of <br />
                Years to Provide:</strong></td>
              <td><input value="<?php echo($row && isset($row['number_years']) ? $row['number_years'] : '');?>" name="textfield6" type="text" class="field" id="textfield6" size="10" /></td>
            </tr>
            <!--<tr>
              <td align="right"><strong>Inflation:</strong></td>
              <td><input name="textfield7" type="text" class="field" id="textfield7" value="" size="20" />              </td>
            </tr>-->
          </table>
        </div>  
        <?php endif;?>      
        
        <?php if(isset($_GET['act']) && $_GET['act'] == 'Expense'):?>
        <div id="expense">
          <table border="0" cellpadding="7" cellspacing="0">
            <tr>
              <td width="130" align="right" valign="top"><strong>Loans:</strong></td>
              <td valign="top"><table border="0" cellpadding="3" cellspacing="0">
              <?php 
              if($row && isset($row['loans'])):
              ?>
              <?php 
              foreach($row['loans'] as $k => $v):
              ?>
                  <tr id="loans_<?php echo $k;?>">
                    <td width="133">
                    	<input name="loans_duration[]" type="text" class="field" id="textfield" value="<?php echo $v['duration']?>" size="25" onfocus="if(this.value==0) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
                    	<input value="<?php echo $v['id'];?>" type="hidden" name="loans_id[]"/>
                    </td>
                    <td width="133"><input name="loans_amount[]" type="text" class="field" id="textfield9" value="<?php echo $v['amount_per_month']?>" size="25" onfocus="if(this.value==0) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
                      <a href="#" onclick="addFormField(); return false;"></a> </td>
                    <?php if($k==0):?>
                    <td width="29" abbr="left"><a href="#" onclick="addFormField(); return false;"><img src="<?php echo img_link('add.gif');?>" alt="Add" border="0" /></a></td>
                    <?php else:?>
                    <td width="29" abbr="left"><a href="#" onclick="$('#loans_<?php echo $k?>').remove(); return false;" class="delete">Delete</a></td>
                    <?php endif;?>
                  </tr>
              <?php 
              endforeach;
              ?>
              <?php 
              else:
              ?>
              	<tr>
                    <td width="133">
                    	<input name="loans_duration[]" type="text" class="field" id="textfield" value="Duration" size="25" onfocus="if(this.value=='Duration') this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
                    	<input type="hidden" name="loans_id[]"/>
                    </td>
                    <td width="133"><input name="loans_amount[]" type="text" class="field" id="textfield9" value="Amount/Month" size="25" onfocus="if(this.value=='Amount/Month') this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
                      <a href="#" onclick="addFormField(); return false;"></a> </td>
                    <td width="29" align="left"><a href="#" onclick="addFormField(); return false;"><img src="<?php echo img_link('add.gif');?>" alt="Add" border="0" /></a></td>
                  </tr>
              <?php 
              endif;	
              ?>
                </table>
                  <input type="hidden" id="hidd" value="hidd" />
                  <div id="divTxt"></div>                  </td>
            </tr>
            <tr>
              <td align="right" valign="top"><strong>Dependant:</strong></td>
              <td valign="top"><table border="0" cellpadding="3" cellspacing="0">
              <?php 
              if($row && isset($row['dependants'])):
              foreach($row['dependants'] as $k => $v):
              ?>
                  <tr id="dep_<?php echo $k;?>">
                    <td>
                    	<input name="dep_duration[]" type="text" class="field" id="textfield3" value="<?php echo $v['duration'];?>" size="25" onfocus="if(this.value==0) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
                    	<input name="dep_id[]" type="hidden" value="<?php echo $v['id'];?>"/>
                    </td>
                    <td><input name="dep_amount[]" type="text" class="field" id="textfield4" value="<?php echo $v['amount_per_month'];?>" size="25" onfocus="if(this.value==0) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
                      <a href="#" onclick="addFormField2(); return false;"></a></td>
                    <?php if($k==0):?>
                    <td><a href="#" onclick="addFormField2(); return false;"><img src="<?php echo img_link('add.gif');?>" border="0" alt="Add" /></a></td>
                    <?php else:?>
                    <td><a href="#" onclick="$('#dep_<?php echo $k;?>').remove(); return false;" class="delete">Delete</a></td>
                    <?php endif;?>
                  </tr>
              <?php 
              endforeach;
              else:
              ?>
              	<tr>
                    <td>
                    	<input name="dep_duration[]" type="text" class="field" id="textfield3" value="Duration" size="25" onfocus="if(this.value=='Duration') this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
                    	<input name="dep_id[]" type="hidden"/>
                    </td>
                    <td><input name="dep_amount[]" type="text" class="field" id="textfield4" value="Amount/Month" size="25" onfocus="if(this.value=='Amount/Month') this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
                      <a href="#" onclick="addFormField2(); return false;"></a></td>
                    <td><a href="#" onclick="addFormField2(); return false;"><img src="<?php echo img_link('add.gif');?>" border="0" alt="Add" /></a></td>
                  </tr>
              <?php 
              endif;
              ?>
                </table>
                  <input type="hidden" id="depen" value="depen" />
                  <div id="divdepen"></div>                  </td>
            </tr>
          </table>
        </div>
        <?php endif;?>
        
        <?php if(isset($_GET['act']) && $_GET['act'] != ''):?>
            <div id="submitbut" style="padding-left:152px;">
   					<input name="btnCalculate" type="submit" class="large button green" value="Calculate"/>
   					<input type="hidden" value="0" name="submit"/>
    		</div> 
    	<?php endif;?>      
		</td>
      </tr>
      
      <tr>
        <td valign="top">
        
        <div id="graph" style="display:<?php echo(isset($_GET['act']) ? 'block' : 'none');?>"> 

<br />
<br />
 <?php $this->load->view('prot_death/chart');?>
            <table border="0" cellpadding="7" cellspacing="0">
              <tr>
                <td align="left"><strong>Explanation:</strong></td>
              </tr>
              <tr>
                <td align="left"><textarea name="Explanation" cols="60" rows="6" class="field" id="textfield3"><?php echo($row && isset($row['explanation']) ? $row['explanation'] : '');?></textarea></td>
              </tr>
              <tr>
                <td align="right">
                <input name="btnSubmit" type="submit" class="large button red" value="Submit"/>
                <input type="hidden" value="1" name="submit"/>
                </td>
              </tr>
          </table>
          </form>

<br />
</div>
        
        </td>
      </tr>
      <tr>
        <td valign="top"></td>
      </tr>
    </table>
    
    <br />
<br />
<a href="JavaScript:window.close();"><img src="<?php echo img_link('cwindow.jpg');?>" alt="Close Window" width="82" height="15" border="0" /></a>
 
</div>

<script language="javascript"> 
	function ShowDiv(){
		//safeToggleFieldDisplay('one');
		//safeToggleFieldDisplay('two');
		//safeToggleFieldDisplay(document.getElementById('three'),'none');
		//safeToggleFieldDisplay(document.getElementById('four'),'none');
 
		var dropdown = document.getElementById("child");
		var index = dropdown.selectedIndex;
		var selectedDIV = dropdown.options[index].value;
		safeToggleFieldDisplay(selectedDIV);
	}
	
	function safeToggleFieldDisplay(field){
		try{
			 if(field == '0'){
				document.getElementById('income').style.display = 'none';
				document.getElementById('expense').style.display = 'none';
				document.getElementById('submitbut').style.display = 'none';
			}
			else if(field == 'Income Approach'){
				document.getElementById('income').style.display = 'block';
				document.getElementById('expense').style.display = 'none';
				document.getElementById('submitbut').style.display = 'block';
			}
			else if(field == 'Expense Approach'){
				document.getElementById('income').style.display = 'none';
				document.getElementById('expense').style.display = 'block';
				document.getElementById('submitbut').style.display = 'block';
			} 

		}
		catch(exception){
			//no handling - just preventing page explosions
		}
	}
 
	//ShowDiv();
</script> 
<?php $this->load->view('layout/footer_data_form');?>